<template>
  <div class="home-acc-info">
    <div class="title">
      <span class="title-first">账户信息</span>
      <span class="title-second">(共{{ total }}个账户)</span>
      <ui-button class="only-btn-arrow">
        <img class="img-logo" src="@/assets/image/home/arrow.png" alt="" />
      </ui-button>
    </div>
    <div class="acc-info-display">
      <div class="arrow-btn left">
        <ui-button class="only-btn" @click="changeTo('prev')">
          <img class="item-img" src="@/assets/image/home/leftPage.png" alt="" />
        </ui-button>
      </div>
      <ui-carousel ref="carousel" class="acc-carousel-new" :autoplay="false" arrow="never" :interval="4000" type="card" height="170px" width="440px">
        <ui-carousel-item v-for="(item, index) in accList" :key="index">
          <div class="acc-item" :style="{ background: 'url(' + url + ') no-repeat center' }">
            <p class="first-p">
              <img class="img-logo" src="@/assets/image/home/logo.png" alt="" />
              <span class="item-type">基本户</span>
            </p>
            <p class="second-p">
              <span v-if="!item.accHide" class="item-acc">{{ item.accNo | formatStringFilter }}</span>
              <span v-else class="item-acc">{{ item.accNo | wordcutFilter(4, 4, 8) | formatStringFilter }}</span>
            </p>
            <p class="item-p">
              <span class="item-num" v-if="!item.accHide"><span class="item-num-mark">￥</span> {{ item.accBalance | numberFilter(2) }}</span>
              <span class="item-num" v-else><span class="item-num-mark">￥</span> {{ item.accNoHide }}</span>
              <ui-button @click="hideNum(index)" class="img-see"></ui-button>
            </p>
            <p class="item-text">
              <span class="item-amount">可用余额</span>
            </p>
            <p class="item-btn">
              <ui-button plain size="small" type="primary">转账</ui-button>
              <ui-button plain size="small" type="primary">明细</ui-button>
              <ui-button plain size="small" type="primary">详情</ui-button>
            </p>
          </div>
        </ui-carousel-item>
      </ui-carousel>
      <div class="arrow-btn right">
        <ui-button class="only-btn" @click="changeTo('next')">
          <img class="item-img" src="@/assets/image/home/rightPage.png" alt="" />
        </ui-button>
      </div>
    </div>
    <ui-dialog
      title="账户详情"
      :visible.sync="showDetail"
      width="60%"
      modal
      close-on-click-modal
      close-on-press-escape
      center
      :append-to-body="true"
      :show-close="false"
    >
      <!-- 活期账户 - 详情 -->
      <table class="detail-info-table">
        <tr>
          <td class="detail-info-table-title" width="15%">账号</td>
          <td width="35%">{{ formDetail.acNo | formatStringFilter }}</td>
          <td class="detail-info-table-title" width="15%">账户状态</td>
          <td width="35%">{{ $msg('accountNatureDict')[formDetail.accountNature] || formDetail.accountNature }}</td>
        </tr>
        <tr>
          <td class="detail-info-table-title">账户名称</td>
          <td>{{ formDetail.accountName }}</td>
          <td class="detail-info-table-title">币种</td>
          <td>{{ $msg('currencyDict')[formDetail.currency] || formDetail.currency }}</td>
        </tr>
        <tr>
          <td class="detail-info-table-title">账户别名</td>
          <td>{{ formDetail.acAliase }}</td>
          <td class="detail-info-table-title">账户类型</td>
          <td>{{ formDetail.accountType }}</td>
        </tr>
        <tr>
          <td class="detail-info-table-title">账户性质</td>
          <td>{{ formDetail.accountNature }}</td>
          <td class="detail-info-table-title">开户日期</td>
          <td>{{ formDetail.openDate | dateFilter('YYYY.MM.DD') }}</td>
        </tr>
        <tr>
          <td class="detail-info-table-title">开户网点</td>
          <td>{{ formDetail.openBranch }}</td>
          <td class="detail-info-table-title">网点行号</td>
          <td>{{ formDetail.openBranchNum }}</td>
        </tr>
        <tr>
          <td class="detail-info-table-title">账户余额</td>
          <td>{{ formDetail.acBalance | numberFilter(3) }}</td>
          <td class="detail-info-table-title">可用余额</td>
          <td>{{ formDetail.availableBalance | numberFilter(3) }}</td>
        </tr>
      </table>

      <div slot="footer">
        <ui-button class="primary-btn" @click="showDetail = false">返回</ui-button>
      </div>
    </ui-dialog>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import systemApi from '@/api/system';
export default {
  data() {
    return {
      total: 3,
      accList: [],
      formDetail: {},
      url: '',
      showDetail: false, // 详情弹窗!
    };
  },
  computed: {
    ...mapState('vxadmin/theme', ['activeName']),
  },

  created() {
    this.url = require(`@/assets/image/theme/${this.activeName}/oval.png`);

    systemApi.accViewQry({}).then((res) => {
      // 模拟接口
      this.accList = res.accList || [];
      this.accList.forEach((item) => {
        item.accNoHide = '****************';
        item.accHide = false;
      });
      this.total = this.accList.length;
    });
  },
  watch: {
    // 监听主题变化，赋值新的背景图片
    activeName(newVal) {
      this.url = require(`@/assets/image/theme/${newVal}/oval.png`);
    },
  },

  methods: {
    /**
     * hideNum
     * 隐藏账户信息
     */
    hideNum(index) {
      this.accList[index].accHide = !this.accList[index].accHide;
      this.$forceUpdate();
    },
    /**
     * 切换上一个或下一个
     * 手动触发
     */
    changeTo(active) {
      if (active == 'prev') {
        this.$refs.carousel.prev();
      } else {
        this.$refs.carousel.next();
      }
    },
    async getDetail(id) {
      try {
        // this.isLoading = true;
        const res = await systemApi.getAccountCurrentDetail(id);
        this.formDetail = res.data;
      } catch (err) {
        this.$message.error(err.message);
      } finally {
        // 关闭加载
        // this.isLoading = false;
        this.showDetail = true;
      }
    },
  },
};
</script>

<style lang="scss">
.home-acc-info {
  background: $color-bg-default;
  border-radius: 8px;
  box-shadow: 0px 1px 10px 0px rgba(0, 21, 41, 0.07);
  .title {
    // display: flex;
    // justify-content: space-between;
    margin: 20px 30px 0px 30px;
    .title-first {
      font-size: $s16;
      text-align: left;
      color: $color-text-main;
    }
    .title-second {
      margin-left: 10px;
      font-size: $s12;
      color: #979797;
    }
  }
  .acc-info-display {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    position: relative;
    .arrow-btn {
      margin: 0 auto;
    }
    .left {
      position: absolute;
      left: 13px;
      top: 34%;
    }
    .right {
      position: absolute;
      top: 34%;
      right: 13px;
    }
  }
  .only-btn {
    border: none;
    padding: 0;
  }
  .only-btn-arrow {
    border: none;
    padding: 5px;
    float: right;
  }
  .acc-carousel-new {
    margin-left: 10%;
    width: 80%;
    margin: 20px auto;
    min-width: 400px;
    .acc-item {
      text-align: center;
      background: url(~@/assets/image/home/oval.png) no-repeat center;
      // background-size: cover;
      height: 100%;
      margin: 0;
      border-radius: 8px;
      box-shadow: 0px 1px 10px 0px rgba(0, 21, 41, 0.07);
      .ui-carousel__item:nth-child(2n) {
        background: #99a9bf;
      }

      .ui-carousel__item:nth-child(2n + 1) {
        background: #d3dce6;
      }
      & p {
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
      }
      .first-p {
        height: 50px;
      }
      .second-p {
        justify-content: flex-end;
      }
      .img-logo {
        margin-top: 10px;
        margin-left: -10px;
      }
      .item-type {
        font-size: $s14;
        font-weight: 200;
        color: $color-text-primary;
        line-height: 20px;
        letter-spacing: 0px;
        margin-left: auto;
        margin-right: 20px;
        margin-top: 15px;
      }
      .item-acc {
        font-size: $s14;
        font-weight: 500;
        color: $color-text-primary;
        line-height: 27px;
        letter-spacing: 0px;
        padding-right: 20px;
      }
      .item-p {
        height: 24px;
        justify-content: space-around;
        .item-num {
          font-size: $s18;
          color: $color-text-primary;
          line-height: 21px;
          .item-num-mark {
            font-size: $s12;
          }
        }
        .img-see {
          height: 15px;
          width: 12px;
          padding: 0px 20px;
          border: none;
          background: url(~@/assets/image/home/see.png) no-repeat center;
        }
      }
      .item-amount {
        height: 17px;
        font-size: $s12;
        font-weight: 200;
        color: $color-text-primary;
        line-height: 17px;
        letter-spacing: 0px;
        margin-left: 10px;
        margin-bottom: 10px;
      }
      .item-btn {
        justify-content: space-around;
        padding: 0 10px;
        .ui-button {
          width: 60px;
          height: 22px;
          padding: 0px;
          background: $color-bg-btn-primary;
          color: white;
          border-color: white;
        }
      }
    }
  }
  .is-active {
    .ui-carousel__button {
      width: 20px;
      height: 6px;
      background: #c39842;
      border-radius: 3px;
    }
  }
  .ui-carousel__button {
    width: 6px;
    height: 6px;
    opacity: 0.5;
    background: #b1b6ce;
    border-radius: 50%;
  }
}
</style>
